-- @owner: @zhanghuan96
-- @date: 2024/11/5
-- @testpoint: GMS_XMLGEN.GETXMLTYPE语法1，参数2dtdOrSchema取值测试，部分步骤合理报错
@conn PrimaryDbAmode;
--前置条件
drop extension if exists gms_xmlgen;
create extension gms_xmlgen;
set behavior_compat_options = 'bind_procedure_searchpath';
--step1:建表;expect:成功
drop table if exists t_getxmltype0004;
create table t_getxmltype0004 (
    during tsrange,
    col2 uuid,
    col3 jsonb,
    set hll(14));
insert into t_getxmltype0004 values('[2010-01-01 14:30,2010-01-01 15:30)',
'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11',
 '{"foo": [true, "bar"], "tags": {"a": 1, "b": null}}'::jsonb,
 hll_empty(14,-1)
);

--step2:参数2取值为-1;expect:报错
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,-1);
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step3:select使用，参数2为-1;expect:报错
select gms_xmlgen.getxmltype('select * from t_getxmltype0004', -1);
--step4:call使用，参数2为-1;expect:报错
call gms_xmlgen.getxmltype('select * from t_getxmltype0004', -1);
--step5:参数2取值为2^32;expect:报错
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,2^32);
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/

--step6:参数2取值为小数;expect:成功
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,1897.2556);
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step7:参数2为小数;expect:成功，向下取整
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,4294967295.5556);
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step8:参数2取值为null;expect:报错
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,null);
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step9:参数2取值为'';expect:报错
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,'');
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step10:参数2取值为表达式;expect:成功
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,16+1465456);
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step11:参数2取值为类型转换;expect:成功
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,1465456::int);
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step12:参数2取值为'abc';expect:报错
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,'abc');
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step13:参数取值为数字加引号;expect:成功
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_cxt := gms_xmlgen.newcontext('select * from t_getxmltype0004');
xml_type := gms_xmlgen.getxmltype(xml_cxt,'1');
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step14:清理环境;expect:成功
drop table if exists t_getxmltype0004;
drop extension if exists gms_xmlgen;